<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model {

	public $variable;

	public function __construct()
	{
		parent::__construct();
		
	}
	

	//修改用户信息
	  public function changeUserInfo($where,$data){
	      return $this->db->where($where)->update('admin',$data);
	  }
	
	//获取用户信息
	  public function getUserInfo($where){
	      return $this->db
	                  ->select('a.*,r.position,r.operation')
	                  ->from('admin as a')
	                  ->join('rights as r','a.rid=r.id')
	                  ->where($where)
	                  ->get()
	                  ->row_array();
	  }
	//IP封锁检查
	  public function isIPBlock(){
	      $res = $this->db->order_by('time','DESC')->where(array('ip'=>$this->input->ip_address()))->get('ipblock')->result_array();
	        if(count($res)>15){
	            if(time() - $res[0]['time'] > 300){
	                $this->db->where(array('ip'=>$this->input->ip_address()))->delete('ipblock');
	                return TRUE;
	            }else{
	                return FALSE;
	            }
	        }else{
	            return TRUE;
	        }
	  }
	  //IP记录
  public function addIpBlock(){
      $this->db->insert('ipblock', array(
          'ip'=>$this->input->ip_address(),
          'time'=>time()
      ));
  }

  //获取分类信息
  public function getBankList(){
      return $this->db->get('bank')->result_array();
  }

  //添加常用客户
  public function addPhrase($data){
  	if($this->db->insert('agent', $data)){
  		return TRUE;
  	}else{
  		return FALSE;
  	}
  }

  //得到常客
	public function getRegulars(){
		return $this->db->get('agent')->result_array();
	}

  //添加商家信息
  public function addBusiness(){
  	if($this->db->insert('business', $data)){
  		return TRUE;
  	}else{
  		return FALSE;
  	}
  }

  //得到商家信息
  public function getBusiness(){
  	return $this->db->get('business')->result_array();
  }
}

/* End of file User_model.php */
/* Location: ./application/models/User_model.php */

